﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Globalization;

namespace SystemX.Infrastructure
{
	public class CountryData
	{
		public string EnglishName { get; set; }
		public string TwoLetterISORegionName { get; set; }

		public static List<CountryData> Countries {
			get
			{
				var retVal = new List<CountryData>();
				foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
				{
					RegionInfo ri = new RegionInfo(ci.Name);
					if (retVal.SingleOrDefault(x => x.EnglishName == ri.EnglishName.ToLowerInvariant()) == null)
					{
						retVal.Add(new CountryData { 
							EnglishName=ri.EnglishName.ToLowerInvariant(),
							TwoLetterISORegionName=ri.TwoLetterISORegionName.ToLowerInvariant()
						});
					}
				}

				// Add custom cultures
				if (retVal.SingleOrDefault(x => x.EnglishName == "bangladesh") == null) {
					retVal.Add(new CountryData {
						EnglishName = "bangladesh",
						TwoLetterISORegionName="bd"
					});
				}

				retVal=retVal.OrderBy(x=>x.EnglishName).ToList();

				return retVal;
			}
		}
	}
}
